#!/bin/bash
gitDir=/usr/local/git/lphome
tomcatDir=/usr/local/apache-tomcat-7.0.70
backupDir=/usr/local/backup
env=pro
echo "===> start lphome deploy"
echo "===> shutdown tomcat server"
cd $tomcatDir/bin
./shutdown.sh
cd $tomcatDir/webapps

echo "===> backup ROOT start..."
timestamp=$(date +%Y-%m-%d:%H:%M:%S)
cp -rf $tomcatDir/webapps/ROOT  $backupDir/ROOT_${timestamp}
echo "===> backup success"

echo "delete ROOT dir "
rm -rf ROOT* 
sleep 3

cd $gitDir
echo "===> git pull "
git pull 
sleep 3
echo "===> mvn begin"
mvn clean install -Dmaven.test.skip=true -P $env
echo "===> mvn compile end "


cd  $gitDir/target/
echo "===> cp ROOT.war  to tomcat Webapp "

cp -rf ROOT.war  $tomcatDir/webapps/ROOT.war
sleep 3
cd $tomcatDir/bin
./startup.sh

tail -f  $tomcatDir/logs/catalina.out


